/*
 *  Line.cpp
 *  SoundController0002
 *
 *  Created by jiro on 10/06/28.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#include "Line.h"

namespace sc 
{

	Line::Line( Type type, double startX, double startY, double endX, double endY )
		: type( type ),
		  startX( startX ),
		  startY( startY ),
		  endX( endX ),
		  endY( endY )
	{}

	Line::~Line()
	{}

	bool Line::operator == ( const Line& rhs ) const
	{
		if ( type == rhs.type && 
			 startX == rhs.startX &&
			 startY == rhs.startY &&
			 endX == rhs.endX &&
			 endY == rhs.endY )
		{
			return true;
		}
		return false;
	}

	bool Line::operator != ( const Line& rhs ) const
	{
		return ! ( *this == rhs );
	}

	bool Line::operator < ( const Line& rhs ) const
	{
		bool isEqual;
		
		isEqual = type == rhs.type;
		if ( ! isEqual )
		{
			return type < rhs.type;
		}
		
		isEqual = startX == rhs.startX;
		if ( ! isEqual )
		{
			return startX < rhs.startX;
		}
		
		isEqual = startY == rhs.startY;
		if ( ! isEqual )
		{
			return startY < rhs.startY;
		}
		
		isEqual = endX == rhs.endX;
		if ( ! isEqual )
		{
			return endX < rhs.endX;
		}

		isEqual = endY == rhs.endY;
		if ( ! isEqual )
		{
			return endY < rhs.endY;
		}
		return false;
	}
		
	bool Line::operator > ( const Line& rhs ) const
	{
		bool isEqual;
		
		isEqual = type == rhs.type;
		if ( ! isEqual )
		{
			return type > rhs.type;
		}
		
		isEqual = startX == rhs.startX;
		if ( ! isEqual )
		{
			return startX > rhs.startX;
		}
		
		isEqual = startY == rhs.startY;
		if ( ! isEqual )
		{
			return startY > rhs.startY;
		}
		
		isEqual = endX == rhs.endX;
		if ( ! isEqual )
		{
			return endX > rhs.endX;
		}

		isEqual = endY == rhs.endY;
		if ( ! isEqual )
		{
			return endY > rhs.endY;
		}
		return false;
	}

	bool Line::operator <= ( const Line& rhs ) const
	{
		return ! ( *this > rhs );
	}
		
	bool Line::operator >= ( const Line& rhs ) const
	{
		return ! ( *this < rhs );
	}

	Line::Type Line::GetType() const
	{
		return type;
	}

	double Line::GetStartX() const
	{
		return startX;
	}

	double Line::GetStartY() const
	{
		return startY;
	}

	double Line::GetEndX() const
	{
		return endX;
	}

	double Line::GetEndY() const
	{
		return endY;
	}

	std::string Line::ToString( Type type ) const
	{
		switch( type ) {
		case Type_Straight:
			return "Straight";
		case Type_ConvexParabola:
			return "ConvexParabola";
		case Type_ConcateParabola:
			return "ConcateParabola";
		case Type_Parabola:
			return "Parabola";
		case Type_Null:
			return "Null";
		default:
			return "";
		}
	}

	std::string Line::ToString() const
	{
		std::stringstream ss;
		ss << "Line: " << ToString( type ) << ", startX: " << startX << ", endX: " << endX << ", startY:" << startY << ", endY: " << endY;
		return ss.str();
	}

}
